<?php

/**
 * redirection actions.
 *
 * @package    lezgro
 * @subpackage redirection
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class redirectionActions extends sfActions {

    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeRedirect(sfWebRequest $request) {
        $query = trim($request->getParameter('query'), '/');
        $redirect = Doctrine::getTable('Redirection')->findOneByUrlFrom($query);
        if ($redirect) {
            sfContext::getInstance()->getConfiguration()->loadHelpers('Url');
            $url_to = url_for($redirect->getUrlTo());
            $this->redirect($url_to);
        } else {
            $q_array = explode('/', $query);
            if(isset($q_array[1])) {
                $this->forward($q_array[0], $q_array[1]);
            } else {
                $this->forward($q_array[0], 'index');
            }
        }
    }

}
